//
//  AYSCategoryTableViewCell.m
//  AiYingShiProject
//
//  Created by lanou on 15/10/28.
//  Copyright © 2015年 李晓理. All rights reserved.
//

#import "AYSCategoryTableViewCell.h"
#import "AYSCategoryCollectionViewCell.h"
#import "AYSCommonPlayViewController.h"
#import <UIImageView+WebCache.h>

@interface AYSCategoryTableViewCell () <UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, strong) NSArray *dataSource;
@property (nonatomic, strong) UICollectionView *mainCollectionView;

@property (nonatomic, strong) AYSCommonPlayViewController *playVC;

@end

@implementation AYSCategoryTableViewCell

- (void)reloadCollectionViewData
{
    [_mainCollectionView reloadData];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        _title = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, SCREEN_WIDTH - 10, 20)];
        _title.textColor = [UIColor whiteColor];
        [self.contentView addSubview:_title];
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.minimumLineSpacing = 10;
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        layout.itemSize = CGSizeMake(100, 220 - 30);
        
        _mainCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 30, SCREEN_WIDTH, 220 - 35) collectionViewLayout:layout];
        [_mainCollectionView registerClass:[AYSCategoryCollectionViewCell class] forCellWithReuseIdentifier:@"AYSCategoryCollectionViewCell"];
        _mainCollectionView.delegate = self;
        _mainCollectionView.dataSource = self;
        [self.contentView addSubview:_mainCollectionView];
    }
    return self;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 15;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    AYSCategoryCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"AYSCategoryCollectionViewCell" forIndexPath:indexPath];
    [cell configureCellWithModel:_dataSource[indexPath.item]];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSIndexPath *newIndexPath = [((UITableView *)self.superview.superview) indexPathForCell:self];
    NSLog(@"item == %ld", indexPath.item);
    NSLog(@"row == %ld", newIndexPath.row);
    _clickItem(indexPath.item);
}

- (void)configureModelArray:(NSArray *)modelArray
{
    _dataSource = modelArray;
}

@end
